class CarModelsController < ApplicationController
  def new
  	@car_model = CarModel.new
  end

  def create
  	@car_model = CarModel.new post_params
    if @car_model.save
       redirect_to car_brand_path(:id =>@car_model.car_brand.id)
    else
      render :action => 'new'
    end
  end

  def destroy
    @car_model = CarModel.find params[:id]
    @car_model.destroy
    redirect_to car_brand_path(:id =>@car_model.car_brand.id)
  end

   def post_params
    params.require(:car_model).permit(*%w(name car_brand_id))
  end
end
